package com.wolfstreet.wsonline.util;

import java.io.File;

import com.wolfstreet.wsonline.WSOApplication;
import com.wolfstreet.wsonline.Constant;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * 
 * @author silence
 * @version [版本号, 2012-7-13]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class ImageDisk {

	private static ImageDisk disk_instance;

	private ImageDisk() {

	}

	public static ImageDisk getIntance() {
		if (disk_instance == null) {
			return new ImageDisk();
		}
		return disk_instance;
	}

	/**
	 * sd卡文件
	 * 
	 * @param url
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	public boolean contains(String md5_name) {
		File f;
		if (WSOApplication.getInstance().sdCardIsExist) {
			f = new File(WSOApplication.getInstance().SD_PATH
					+ Constant.IMG_PATH + md5_name);
		} else {
			f = new File(Constant.IMG_APP_PATH + md5_name);
		}
		return FileHelper.isFileExist(f);
	}

	/**
	 * 获取图片 <功能详细描述>
	 * 
	 * @param path
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	public Bitmap getBitmap(String path) {
		Bitmap temp = BitmapFactory.decodeFile(path);
		Bitmap temp1 = Util.toRoundCorner(temp,
				5 * WSOApplication.getInstance().density);
		if (temp != null) {
			temp.recycle();
		}
		return temp1;
	}

	/**
	 * 获取图片 <功能详细描述>
	 * 
	 * @param path
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	public Bitmap getAdBitmap(String path) {
		Bitmap temp = BitmapFactory.decodeFile(path);
		return temp;
	}

	/**
	 * 清空
	 */
	public void clear() {
		if (WSOApplication.getInstance().sdCardIsExist) {
			FileHelper.delAllFile(WSOApplication.getInstance().SD_PATH
					+ Constant.IMG_PATH);
		} else {
			FileHelper.delAllFile(Constant.IMG_APP_PATH);
		}
	}
}